package us.wili.dev.platform.config;

import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * Created by JasonY on 18/7/25.
 */
@Configuration
@ConfigurationProperties(ignoreUnknownFields = false, prefix = "kaptcha")
public class KaptchaConfig {

    private Properties properties;

    public Properties getProperties() {
        return properties;
    }

    public void setProperties(Properties properties) {
        this.properties = properties;
    }

    @Bean
    public Producer captchaProducer() {
        Config config = new Config(properties);

        DefaultKaptcha producer = new DefaultKaptcha();
        producer.setConfig(config);
        return producer;
    }
}
